package com.pgybook.db.entity.mapper;

import org.springframework.stereotype.Repository;
import com.pgybook.db.entity.domain.Book;
import com.pgybook.db.entity.domain.BookEx;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;

@Repository
public interface BookMapper {
    int countByExample(BookEx example);

    int deleteByExample(BookEx example);

    @Delete({
            "delete from book",
            "where BOOKID = #{bookid,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long bookid);

    @Insert({
            "insert into book (PUBLISHERID, NAME, ",
            "ISBN, AUTHOR1, AUTHOR2, ",
            "AUTHOR3, PUBTIME, PAGECNT, ",
            "PAPERSIZE, PACKING, ",
            "PRICE, WEIGHT, LANGUAGE, ",
            "STATUS, RECOMLEVEL, ",
            "CRTTIME, UPDTIME, ",
            "CRTSTAFF, UPDSTAFF, ",
            "CONTENT)",
            "values (#{publisherid,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, ",
            "#{isbn,jdbcType=VARCHAR}, #{author1,jdbcType=INTEGER}, #{author2,jdbcType=INTEGER}, ",
            "#{author3,jdbcType=INTEGER}, #{pubtime,jdbcType=DATE}, #{pagecnt,jdbcType=INTEGER}, ",
            "#{papersize,jdbcType=VARCHAR}, #{packing,jdbcType=VARCHAR}, ",
            "#{price,jdbcType=DECIMAL}, #{weight,jdbcType=INTEGER}, #{language,jdbcType=INTEGER}, ",
            "#{status,jdbcType=INTEGER}, #{recomlevel,jdbcType=INTEGER}, ",
            "#{crttime,jdbcType=TIMESTAMP}, #{updtime,jdbcType=TIMESTAMP}, ",
            "#{crtstaff,jdbcType=INTEGER}, #{updstaff,jdbcType=INTEGER}, ",
            "#{content,jdbcType=LONGVARCHAR})"
    })
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "bookid", before = false, resultType = Long.class)
    int insert(Book record);

    int insertSelective(Book record);

    List<Book> selectByExampleWithBLOBs(BookEx example);

    List<Book> selectByExample(BookEx example);

    @Select({
            "select",
            "BOOKID, PUBLISHERID, NAME, ISBN, AUTHOR1, AUTHOR2, AUTHOR3, PUBTIME, PAGECNT, ",
            "PAPERSIZE, PACKING, PRICE, WEIGHT, LANGUAGE, STATUS, RECOMLEVEL, CRTTIME, UPDTIME, ",
            "CRTSTAFF, UPDSTAFF, CONTENT",
            "from book",
            "where BOOKID = #{bookid,jdbcType=BIGINT}"
    })
    @ResultMap("ResultMapWithBLOBs")
    Book selectByPrimaryKey(Long bookid);

    int updateByExampleSelective(@Param("record") Book record, @Param("example") BookEx example);

    int updateByExampleWithBLOBs(@Param("record") Book record, @Param("example") BookEx example);

    int updateByExample(@Param("record") Book record, @Param("example") BookEx example);

    int updateByPrimaryKeySelective(Book record);

    @Update({
            "update book",
            "set PUBLISHERID = #{publisherid,jdbcType=INTEGER},",
            "NAME = #{name,jdbcType=VARCHAR},",
            "ISBN = #{isbn,jdbcType=VARCHAR},",
            "AUTHOR1 = #{author1,jdbcType=INTEGER},",
            "AUTHOR2 = #{author2,jdbcType=INTEGER},",
            "AUTHOR3 = #{author3,jdbcType=INTEGER},",
            "PUBTIME = #{pubtime,jdbcType=DATE},",
            "PAGECNT = #{pagecnt,jdbcType=INTEGER},",
            "PAPERSIZE = #{papersize,jdbcType=VARCHAR},",
            "PACKING = #{packing,jdbcType=VARCHAR},",
            "PRICE = #{price,jdbcType=DECIMAL},",
            "WEIGHT = #{weight,jdbcType=INTEGER},",
            "LANGUAGE = #{language,jdbcType=INTEGER},",
            "STATUS = #{status,jdbcType=INTEGER},",
            "RECOMLEVEL = #{recomlevel,jdbcType=INTEGER},",
            "CRTTIME = #{crttime,jdbcType=TIMESTAMP},",
            "UPDTIME = #{updtime,jdbcType=TIMESTAMP},",
            "CRTSTAFF = #{crtstaff,jdbcType=INTEGER},",
            "UPDSTAFF = #{updstaff,jdbcType=INTEGER},",
            "CONTENT = #{content,jdbcType=LONGVARCHAR}",
            "where BOOKID = #{bookid,jdbcType=BIGINT}"
    })
    int updateByPrimaryKeyWithBLOBs(Book record);

    @Update({
            "update book",
            "set PUBLISHERID = #{publisherid,jdbcType=INTEGER},",
            "NAME = #{name,jdbcType=VARCHAR},",
            "ISBN = #{isbn,jdbcType=VARCHAR},",
            "AUTHOR1 = #{author1,jdbcType=INTEGER},",
            "AUTHOR2 = #{author2,jdbcType=INTEGER},",
            "AUTHOR3 = #{author3,jdbcType=INTEGER},",
            "PUBTIME = #{pubtime,jdbcType=DATE},",
            "PAGECNT = #{pagecnt,jdbcType=INTEGER},",
            "PAPERSIZE = #{papersize,jdbcType=VARCHAR},",
            "PACKING = #{packing,jdbcType=VARCHAR},",
            "PRICE = #{price,jdbcType=DECIMAL},",
            "WEIGHT = #{weight,jdbcType=INTEGER},",
            "LANGUAGE = #{language,jdbcType=INTEGER},",
            "STATUS = #{status,jdbcType=INTEGER},",
            "RECOMLEVEL = #{recomlevel,jdbcType=INTEGER},",
            "CRTTIME = #{crttime,jdbcType=TIMESTAMP},",
            "UPDTIME = #{updtime,jdbcType=TIMESTAMP},",
            "CRTSTAFF = #{crtstaff,jdbcType=INTEGER},",
            "UPDSTAFF = #{updstaff,jdbcType=INTEGER}",
            "where BOOKID = #{bookid,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(Book record);
}
